package com.wnxy.sddfp.trade.controller;


import com.wnxy.sddfp.common.model.dto.trade.BorrowRecordDTO;
import com.wnxy.sddfp.common.model.query.BorrowRecordQuery;
import com.wnxy.sddfp.common.model.query.Pages;
import com.wnxy.sddfp.common.model.result.Result;
import com.wnxy.sddfp.common.model.vo.BorrowRecordVo;
import com.wnxy.sddfp.trade.service.IBorrowRecordService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author yellow Docter
 * @date 2023 -07-31
 * @desc
 */
@RestController
public class TradeController {

    @Autowired
    private IBorrowRecordService borrowRecordService;

    @ApiOperation("借款审核接口,同步借款数据")
    @PutMapping("/trade/borrow/status")
    public Result verifyStatus(Integer approveStatus, Long borrowRecordId) {
        String result = borrowRecordService.verifyStatus(approveStatus, borrowRecordId);
        return Result.ok(result);
    }

    @ApiOperation("借款申请")
    @PostMapping("/trade/borrow/add")
    public Result addBorrowRecord(@RequestBody BorrowRecordDTO borrowRecordDTO) {
        borrowRecordService.addBorrowRecord(borrowRecordDTO);
        return Result.ok();
    }

    @ApiOperation("借款记录查询")
    @PostMapping("/trade/borrow/query")
    public Result<Pages<BorrowRecordVo>> queryBorrowRecord(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "2") Integer pageSize,
            @RequestBody BorrowRecordQuery borrowRecordQuery) {
        Pages<BorrowRecordVo> pages =
                borrowRecordService.queryBorrowRecord(pageNum, pageSize, borrowRecordQuery);
        return Result.ok(pages);
    }


    // @ApiOperation("借款申请...")
    // @PostMapping("/auth/trade/borrow")
    // public String borrowRecord(@RequestBody BorrowRecordDTO borrowRecordDTO) {
    //
    //     // 进行 借款
    //     borrowRecordService.borrow(borrowRecordDTO);
    //     return "借款成功...";
    //
    // }
    //
    // @ApiOperation("查询借款记录")
    // @GetMapping("/auth/trade/search")
    // public Result searchborrowRecord(String name, String createDate) {
    //
    //     LambdaQueryWrapper<BorrowRecord> borrowRecordLambdaQueryWrapper = Wrappers.lambdaQuery(BorrowRecord.class);
    //
    //     if (StringUtils.isNotBlank(name)) {
    //         borrowRecordLambdaQueryWrapper.like(BorrowRecord::getName, name);
    //     }
    //     if (StringUtils.isNotBlank(createDate)) {
    //         borrowRecordLambdaQueryWrapper.gt(BorrowRecord::getCreateDate, createDate);
    //     }
    //
    //     List<BorrowRecord> list = borrowRecordService.list(borrowRecordLambdaQueryWrapper);
    //
    //     return Result.ok("查询成功", list);
    // }
    //
    // @ApiOperation("借款记录审核")
    // @GetMapping("/auth/trade/status/{borrowId}/{status}")
    // public String tradeChangeStatus(
    //         @PathVariable("borrowId") Long borrowId,
    //         @PathVariable("status") Integer status) {
    //     String result = borrowRecordService.changeStatus(borrowId, status);
    //     return result;
    // }
    //
    // @ApiOperation("机构认购投资理财产品")
    // @PostMapping("/auth/trade/agency/bid/add/{borrowId}/{amount}")
    // public Result addAgencyBid(
    //         @PathVariable("borrowId") Long borrowId,       // 借款的id
    //         @PathVariable("amount") Integer amount) {      // 投机的金额
    //
    //     // 投资认证流程
    //     Map<String, Object> map = borrowRecordService.addAgencyBid(borrowId, amount);
    //     return Result.ok(map);
    // }
    //
    // @ApiOperation("机构认购投资的审核")
    // @PostMapping("/trade/agency/bid/status")
    // public String agencyBidStatus(
    //         @RequestParam("borrowId") Long borrowId,         // 借款id
    //         @RequestParam("commission") String commission,   // 平台佣金
    //         @RequestParam("status") String status            // 审核状态
    // ) {
    //
    //     String result = borrowRecordService.agencyBidStatus(borrowId, commission, status);
    //     return result;
    //
    // }
}
